<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');
class home extends MY_Controller
{
	function __construct()
	{
		parent::__construct();
		//$this->output->enable_profiler(TRUE);
	}
	
	//首页
	public function index()
	{
		//获取幻灯片
		$query0 = "select * from `crazy_archives` where  FIND_IN_SET('f', flag) order by createtime desc limit 0,4";
		$list0=$this->db->query($query0);
		$data['list0'] =$list0;
		
		//获取工作动态
		$query1_1 = "select * from `crazy_archives` where `typeid`=39 order by createtime desc limit 1,5";
		$query1_2 = "select * from `crazy_archives` where `typeid`=39 order by createtime desc limit 1";
		$gongzuodongtai_top = $this->db->query($query1_2);
		$gongzuodongtai_list = $this->db->query($query1_1);
		$data['gongzuodongtai_top'] = $gongzuodongtai_top->row();
		$data['gongzuodongtai_list'] = $gongzuodongtai_list;
		
		//获取通知公告
		$query2 = "select * from `crazy_archives` where `typeid`=40 order by createtime desc limit 0,11";
		$tontzhigonggao=$this->db->query($query2);
		$data['tontzhigonggao']=$tontzhigonggao;
		
		//行政审批
		$query3 = "select * from `crazy_archives` where `typeid`=17 order by createtime desc limit 0,5";
		$xinghengshenpi=$this->db->query($query3);
		$data['xinghengshenpi']=$xinghengshenpi;
		
		//法规政策
		$query4 = "select * from `crazy_archives` where `typeid`=29 order by createtime desc limit 0,5";
		$list4=$this->db->query($query4);
		$data['list4']=$list4;
		
		//扬尘管理
		$query5 = "select * from `crazy_archives` where `typeid`=20 order by createtime desc limit 0,5";
		$list5=$this->db->query($query5);
		$data['list5']=$list5;
		
		//部门联动
		$query6 = "select * from `crazy_archives` where `typeid`=25 order by createtime desc limit 0,5";
		$list6=$this->db->query($query6);
		$data['list6']=$list6;
		
		//公司管理
		$query7 = "select * from `crazy_archives` where `typeid`=21 order by createtime desc limit 0,5";
		$list7=$this->db->query($query7);
		$data['list7']=$list7;
		
		//表格下载
		$query8 = "select * from `crazy_archives` where `typeid`=35 order by createtime desc limit 0,7";
		$list8=$this->db->query($query8);
		$data['list8']=$list8;
		
		//重要提示
		$query9 = "select * from `crazy_archives` where `typeid`=44 order by createtime desc limit 0,7";
		$list9=$this->db->query($query9);
		$data['list9']=$list9;
		
		$data['css']="index.css";
		
		$this->load->view('home/header',$data);
		
		$this->load->view('home/index', $data);
		
		$this->load->view('home/foot');
		
		
	}
	
	//列表页
	public function newslist()
	{
		$typeid = $this->input->get('typeid', true);
		$keyword = $this->input->get('searchword', true);
		
		
		//根据分类ID获取分类信息
		$model_type=$this->db->from('crazy_sort')->where('id',$typeid)->get()->row();
		if($model_type!=null)
		{
			$data['sort_name']=$model_type->name;
		}
		else
		{
		$data['sort_name']="";
		}
		
		$whereSql = " WHERE 1=1 ";
		if($typeid!=''){
			$whereSql .= " And typeid='$typeid'  ";
		}
		
		  if($keyword != '')
            {
                $whereSql .= " AND ( CONCAT(title) LIKE '%$keyword%') ";
            }
			
			
			
			    $typeid_s=$this->_sort_id_child_list('45');
                   $typeid_s=rtrim($typeid_s,',');
                    $whereSql .= ' AND typeid NOT IN ('.$typeid_s.')';
			
			
		
		$query = "SELECT * FROM `crazy_archives` $whereSql order by createtime desc";
		$list = $this->db->query($query);
		//从数据库中获取列表总数
		$num = $list->num_rows();
		
		//查询条件
		$search_str = "typeid=$typeid";
		
		//分类数据初始化
		$params = array( 
			'total' => $num, 
			'listRows' => '10', 
			'pa' => $search_str 
		);
		
		//分页类初始化
		$this->load->library('Page', $params);
		
		//分页SQL语句
		$search_query = $query . "  limit {$this->page->limit} ";
		
		//获取分页结果
		$reslut_list = $this->db->query($search_query);
		
		$data['list'] = $reslut_list;
		
		$data['page'] = $this->page->fpage();
		
			//重要提示
		$query9 = "select * from `crazy_archives` where `typeid`=44 order by createtime desc limit 0,7";
		$list9=$this->db->query($query9);
		$data['list9']=$list9;
		
		$data['css']="other.css";
		
		$this->load->view('home/header',$data);
		
		$this->load->view('home/list', $data);
		
		$this->load->view('home/foot');
	}
	
	
	
	
	
	 //返回与某个目相关的下级目录的类目ID列表
        public function _sort_id_child_list($id)
        {
            $total_id='';
            $this->load->model('admin/Sort_model');
            $model=$this->Sort_model->get_sort_by_pid($id);
            if ($model->num_rows() > 0)
            {
                foreach($model->result() as $row)
                {
                    $total_id=$total_id.$row->id.','; 
                    $total_id=$total_id.$this->_sort_id_child_list($row->id);
                }
            }

            return $total_id;
        }
	
	
	
	
	//详情页
	public function detail()
	{
		$id = $this->input->get('id', true);
		$model = $this->db->from('crazy_archives')->where('id', $id)->get()->row();
		$data['model'] = $model;
			//重要提示
		$query9 = "select * from `crazy_archives` where `typeid`=44 order by createtime desc limit 0,7";
		$list9=$this->db->query($query9);
		$data['list9']=$list9;
		
		$data['css']="other.css";
		
		$this->load->view('home/header',$data);
		$this->load->view('home/detail', $data);
		$this->load->view('home/foot');
	}
}